import {defineStore} from 'pinia'
import  request  from '@/utils/request'
import {BannerItem, ApiRes,GoodItem, HotGoods, Brand, HomeProduct,Special} from '@/types/data'
export default defineStore('home',{
  state() {
    return {
      bannerList:[] as BannerItem[],
      newGoodList:[] as GoodItem[],
      hotGoodList:[] as HotGoods[],
      brandList:[] as Brand[],
      productList: [] as HomeProduct[],
      specialList: [] as Special[],

    }
  },
  actions:{
    async getBannerList () {
      const res = await request.get<ApiRes<BannerItem[]>>('home/banner')
      this.bannerList = res.data.result
      console.log(res);
      
    },
    async getNewList () {
    setTimeout(async () => {
      const res = await request.get<ApiRes<GoodItem[]>>('/home/new')
      this.newGoodList = res.data.result
     //  console.log(res);
    },2000)
     
    },
    async getHotList() {
      setTimeout(async () => {
        const res = await request.get<ApiRes<HotGoods[]>>('/home/hot')
      this.hotGoodList = res.data.result
      },2000)
    },
    async getBrandList() {
     setTimeout(async() => {
      const res = await request.get<ApiRes<Brand[]>>('/home/brand')
      console.log(res)
      this.brandList = res.data.result
     }, 2000);
    },
    async getProductList() {
      const res = await request.get<ApiRes<HomeProduct[]>>('/home/goods')
      this.productList = res.data.result
    },
    async getSpecialList() {
      const res = await request.get<ApiRes<Special[]>>('/home/special')
      this.specialList = res.data.result
    },
  },

  
  
})